﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;

namespace TestClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            tbColor.Tag = Color.Blue;
            tbColor.Text = Color.Blue.Name;
        }

        private void bSelectColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tbColor.Text = colorDialog1.Color.Name;
                tbColor.Tag = colorDialog1.Color;

            }
        }

        private void bSendUDP_Click(object sender, EventArgs e)
        {
            using (UdpClient c = new UdpClient(tbIP.Text, Convert.ToInt32(tbPortUDP.Text)))
                c.Send(Encoding.UTF8.GetBytes(tbText.Text), tbText.Text.Length);
        }

        private void bSendTCP_Click(object sender, EventArgs e)
        {
            using (TcpClient c = new TcpClient(tbIP.Text, Convert.ToInt32(tbPortTCP.Text)))
            {
                var x = new BinaryWriter(c.GetStream());
                x.Write((int)1);
                x.Write(tbText.Text);
            }
        }

        private void bSendColor_Click(object sender, EventArgs e)
        {

            using (TcpClient c = new TcpClient(tbIP.Text, Convert.ToInt32(tbPortTCP.Text)))
            {
                var x = new BinaryWriter(c.GetStream());
                x.Write((int)2);
                var co = Color.FromName(tbColor.Text);
                x.Write(co.R);
                x.Write(co.G);
                x.Write(co.B);

            }

        }
    }
}

